import unittest

from HTMLTestRunner import HTMLTestRunner
from learn_test.test_case import TestCase
from learn_test.auto_test import AutoTest as Atest

from django3.settings import BASE_DIR
import os
from datetime import time


class AutoTest(unittest.TestCase):

    # def setUp(self):
    #     print('setup')
    #
    # def tearDown(self):
    #     print('teardown')

    @classmethod
    def setUpClass(cls):
        cls.auto = Atest()

    @classmethod
    def tearDownClass(cls):


        print('down')

    def test_01_add(self):
        # auto.test_add(1,4,5)

        self.assertEqual(self.auto.add(1, 3), 4)

    # 不去测试这个
    # @unittest.skip('i dont want to exec')
    def test_02_add(self):
        # auto.test_add(1,4,5)

        self.assertEqual(self.auto.add(1, 3), 5)


def get_test():
    suite = unittest.TestSuite()
    test_one = unittest.TestLoader().loadTestsFromTestCase(AutoTest)
    test_two = unittest.TestLoader().loadTestsFromTestCase(TestCase)
    suite.addTest(test_one)
    suite.addTest(test_two)
    return suite


if __name__ == "__main__":
    filePath = os.path.join(BASE_DIR, 'learn_test', 'test_output1.html')

    # unittest.main(verbosity=3)
    # suite = unittest.TestSuite()
    # 手工加入
    # testcase = [AutoTest('test_01_add'),AutoTest('test_02_add'),TestCase('test_caseone')]
    # suite.addTest(testcase)
    # runner = unittest.TextTestRunner()
    # runner.run(suite)

    # 自动加载
    # testone = unittest.TestLoader().loadTestsFromTestCase(AutoTest)
    # testtwo = unittest.TestLoader().loadTestsFromTestCase(TestCase)
    # suite.addTest([testone, testtwo])
    # runner = unittest.TextTestRunner()
    # runner.run(suite)

    # 测试报告
    # /Users/admin/project/django3/learn_test

    # runner.run(suite)
    with open(filePath, 'wb+') as fp:
        runner = HTMLTestRunner(stream=fp, title='Python Test Report',
                                description='This  is Python  Report')
        runner.run(get_test())
